//
//  BuildingViewController.m
//  OutesIOS
//
//  Created by norman on 2019/6/6.
//  Copyright © 2019 norman. All rights reserved.
//

#import "BuildingViewController.h"
#import "EditorTableViewCell.h"
#import "UITapLabel.h"
#import "CalcTableViewCell.h"
#import "CustomIOSAlertView.h"
#import "TerminalTypeTableViewCell.h"

#define EditCell @"EditCell"
#define CalcCell @"CalcCell"
#define TerCell @"TerCell"

#define SECTION_TITLE_HEIGHT 35

@interface BuildingViewController ()

@property (nonatomic,strong) BuildingData *BuildingData;

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) UIView *coeffView; // 维护结构传热系数

@property (nonatomic,strong) UITextField *textField1;
@property (nonatomic,strong) UITextField *textField2;
@property (nonatomic,strong) UITextField *textField3;
@property (nonatomic,strong) UITextField *textField4;
@property (nonatomic,strong) UITextField *textField5;

@property (nonatomic,strong) UIView *tipView1; // 当地基础室外参数
@property (nonatomic,strong) UIView *tipView2; // 水温要求推荐
@property (nonatomic,strong) UIView *tipView3; // 运行费用
@property (nonatomic,strong) UIView *tipView4; // 设备选型提示


@end

@implementation BuildingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViews];
    // Do any additional setup after loading the view.
}

#pragma mark - 初始化视图
- (void)setupViews{
    self.title = @"建筑信息编辑";
    
    //自定义返回按钮
    UIBarButtonItem *returnBtn = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(onReturn)];
    self.navigationItem.leftBarButtonItem = returnBtn;
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStyleDone target:self action:@selector(saveBuildingData)];
    self.navigationItem.rightBarButtonItem = rightBtn;
    
    self.tableView = [[UITableView alloc] initWithFrame:[UIView frameWithOutNav] style:UITableViewStyleGrouped];
    [self.tableView registerClass:[EditorTableViewCell class] forCellReuseIdentifier:EditCell];
    [self.tableView registerClass:[CalcTableViewCell class] forCellReuseIdentifier:CalcCell];
    [self.tableView registerClass:[TerminalTypeTableViewCell class] forCellReuseIdentifier:TerCell];
    self.tableView.backgroundColor = UIColor16(0xeeeeee);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}

#pragma mark - 事件响应
- (void)onReturn {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)saveBuildingData {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - tableView显示设置数据
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 11;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    } else if (section == 1) {
        return 7;
    } else if (section == 2) {
        return 1;
    } else if (section == 3) {
        return 2;
    } else if (section == 4) {
        return 3;
    } else if (section == 5) {
        return 3;
    } else if (section == 6) {
        // 技术热负荷
        return 4;
    } else if (section == 7) {
        // 设备选型
        return 6;
    } else if (section == 8) {
        return 4;
    } else if (section == 9) {
        return 5;
    } else {
        return 4;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return [self tableView:tableView cellForSection0:indexPath];
    } else if (indexPath.section == 1) {
        return [self tableView:tableView cellForSection1:indexPath];
    } else if (indexPath.section == 2) {
        return [self tableView:tableView cellForSection2:indexPath];
    } else if (indexPath.section == 3) {
        return [self tableView:tableView cellForSection3:indexPath];
    } else if (indexPath.section == 4) {
        return [self tableView:tableView cellForSection4:indexPath];
    } else if (indexPath.section == 5) {
        return [self tableView:tableView cellForSection5:indexPath];
    } else if (indexPath.section == 6) {
        return [self tableView:tableView cellForSection6:indexPath];
    } else if (indexPath.section == 7) {
        return [self tableView:tableView cellForSection7:indexPath];
    } else if (indexPath.section == 8) {
        return [self tableView:tableView cellForSection8:indexPath];
    } else if (indexPath.section == 9) {
        return [self tableView:tableView cellForSection9a:indexPath];
    } else {
        return [self tableView:tableView cellForSection10:indexPath];
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 1 && indexPath.row == 0) {
        [self selectBuildingCoeff];
    } else if (indexPath.section == 1 && indexPath.row == 6) {
        [self selectIsEsBuilding];
    } else if (indexPath.section == 5 && indexPath.row == 0) {
        [self chooseDate:@"选择开始日期" andDate:[NSDate dateYesterday] andCb:^(NSDate *date) {
            
        }];
    } else if (indexPath.section == 5 && indexPath.row == 1) {
        [self chooseDate:@"选择结束日期" andDate:[NSDate new] andCb:^(NSDate *date) {
            
        }];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    if (cell == nil) {
        cell = [[EditorTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:EditCell];
    }
    return [cell getHeight];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        return [self setupTitleView:@"现场条件"];
    } else if (section == 4) {
        return [self setupTitleView:@"使用需求"];
    } else if (section == 4) {
        return [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, DEFAULT_SECTION_HEIGHT)];
    } else if (section == 8) {
        return [self setupTitleView:@"运维分析"];
    } else if (section == 10) {
        return [self setupTitleView:@"系统维护（如需统计，勾选右侧选框）"];
    }
    return [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, CGFLOAT_MIN)];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1 || section == 4 || section == 8 || section == 10) {
        return SECTION_TITLE_HEIGHT;
    } else if (section == 6) {
        return DEFAULT_SECTION_HEIGHT;
    }
    return CGFLOAT_MIN;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == 1) {
        if (self.BuildingData.es_building == 0) {
            return self.coeffView;
        } else {
            return [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, DEFAULT_SECTION_HEIGHT)];
        }
    } else if (section == 2) {
        return self.tipView1;
    } else if (section == 4) {
        return self.tipView2;
    } else if (section == 5) {
        return self.tipView3;
    } else if (section == 6) {
        return [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, DEFAULT_SECTION_HEIGHT)];
    } else if (section == 7) {
        return self.tipView4;
    }
    return [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, CGFLOAT_MIN)];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 1) {
        //节能建筑
        if (self.BuildingData.es_building == 0) {
            return self.coeffView.height;
        } else {
            return DEFAULT_SECTION_HEIGHT;
        }
    } else if (section == 2) {
        return self.tipView1.height;
    } else if (section == 4) {
        return self.tipView2.height;
    } else if (section == 5) {
        return self.tipView3.height;
    } else if (section == 6) {
        return DEFAULT_SECTION_HEIGHT;
    } else if (section == 7) {
        return self.tipView4.height;
    }
    return CGFLOAT_MIN;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection0:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = YES;
    if (indexPath.row == 0) {
        [cell setTitleStr:@"建筑名称" andColor:BSBlackTextColor andHintStr:@"请输入建筑名称" andInputViewIsHidden:NO andInfoStr:nil andUnit:nil];
//        [cell setEditorText:[NSString stringWithFormat:@"%@", self.BuildingData.building_name]];
        [cell setKeyboardType:UIKeyboardTypeDefault];
        cell.TextFiledEditingEndBlock = ^(NSString *value){
            if (value != nil && value.length > 0) {
                self.BuildingData.building_name = [NSString stringWithString:value];
            } else {
                [Tools showMessageCenter:@"建筑名称不能为空！"];
            }
        };
    }
    return cell;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection1:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = YES;
    UITableViewCell *Selectcell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"SelectArea_Cell"];
    Selectcell.textLabel.textColor = CM_TABLE_TITLE_COLOR;
    Selectcell.textLabel.font = [UIFont systemFontOfSize:kListTitleFontSize];
    Selectcell.detailTextLabel.textColor = CM_TABLE_INFO_COLOR;
    
    if (indexPath.row == 0) {
        Selectcell.textLabel.text = @"建筑外形";
        if (self.BuildingData.is_regular == 1) {
            Selectcell.detailTextLabel.text = @"规则";
        } else {
            Selectcell.detailTextLabel.text = @"不规则";
        }
        Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return Selectcell;
    } else if (indexPath.row == 1) {
        [cell setTitleStr:@"建筑长" andColor:nil andHintStr:@"请输入建筑长度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"m"];
        if (self.BuildingData.length > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%d", (int)self.BuildingData.length]];
        }
        [cell setKeyboardType:UIKeyboardTypeNumberPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.length = [value doubleValue];
            }
        };
        return cell;
    } else if (indexPath.row == 2) {
        [cell setTitleStr:@"建筑宽" andColor:nil andHintStr:@"请输入建筑宽度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"m"];
        if (self.BuildingData.width > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%d", (int)self.BuildingData.width]];
        }
        [cell setKeyboardType:UIKeyboardTypeNumberPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.width = [value doubleValue];
            }
        };
        return cell;
    } else if (indexPath.row == 3) {
        [cell setTitleStr:@"平均单层层高" andColor:nil andHintStr:@"请输入层高" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"m"];
        if (self.BuildingData.floor_height > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.floor_height]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.floor_height = [value doubleValue];
            }
        };
        return cell;
    } else if (indexPath.row == 4) {
        [cell setTitleStr:@"采暖区域建筑层数" andColor:nil andHintStr:@"请输入建筑层数" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"层"];
        if (self.BuildingData.floor_count > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%d", (int)self.BuildingData.floor_count]];
        }
        [cell setKeyboardType:UIKeyboardTypeNumberPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value intValue] > 0) {
                self.BuildingData.floor_count = [value intValue];
            }
        };
        return cell;
    } else if (indexPath.row == 5) {
        [cell setTitleStr:@"建筑窗墙比" andColor:nil andHintStr:@"请输入建筑窗墙比" andInputViewIsHidden:NO andInfoStr:nil andUnit:@""];
        if (self.BuildingData.window_rate > 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.window_rate]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.window_rate = [value doubleValue];
            }
        };
         return cell;
    } else {
        Selectcell.textLabel.text = @"是否是节能建筑";
        if (self.BuildingData.es_building == 0) {
            Selectcell.detailTextLabel.text = @"否";
        } else {
            Selectcell.detailTextLabel.text = @"是";
        }
        Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return Selectcell;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection2:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = YES;
    
    if (indexPath.row == 0) {
        [cell setTitleStr:@"室外计算温度" andColor:nil andHintStr:@"请输入室外计算温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"℃"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    }
    return cell;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection3:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = YES;
    
    if (indexPath.row == 0) {
        [cell setTitleStr:@"室内长时间停留人数" andColor:nil andHintStr:@"请输入室外计算温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"个"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%d",(int)self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else {
        [cell setTitleStr:@"机械排风/废气量" andColor:nil andHintStr:@"请输入机械排风/废气量" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"m³/h"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    }
    return cell;
}

// 使用需求
-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection4:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = YES;
    
    if (indexPath.row == 0) {
        [cell setTitleStr:@"设计室温要求" andColor:nil andHintStr:@"请输入室外计算温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"℃"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 1) {
        [cell setTitleStr:@"设计供水水温要求" andColor:nil andHintStr:@"请输入供水水温" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"℃"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    }else {
        [cell setTitleStr:@"设计回水水温要求" andColor:nil andHintStr:@"请输入回水水温" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"℃"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    }
    return cell;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection5:(NSIndexPath *)indexPath {
    UITableViewCell *Selectcell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"SelectArea_Cell"];
    Selectcell.textLabel.textColor = CM_TABLE_TITLE_COLOR;
    Selectcell.textLabel.font = [UIFont systemFontOfSize:kListTitleFontSize];
    Selectcell.detailTextLabel.textColor = CM_TABLE_INFO_COLOR;
    
    if (indexPath.row == 0) {
        Selectcell.textLabel.text = @"供暖开始日期";
        Selectcell.detailTextLabel.text = @"未设置";
        Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else if (indexPath.row == 1) {
        Selectcell.textLabel.text = @"供暖结束日期";
        Selectcell.detailTextLabel.text = @"未设置";
        Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else if (indexPath.row == 2) {
        Selectcell.textLabel.text = @"一天供暖时长";
        EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
        cell.accessoryType = UITableViewCellAccessoryNone;
        [cell setEditorText:@""];
        cell.TextFiledEditingEndBlock = nil;
        cell.editorView.enabled = YES;
        
        [cell setTitleStr:@"一天供暖时长" andColor:nil andHintStr:@"请输入供暖时长" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"小时"];
        [cell setKeyboardType:UIKeyboardTypeNumberPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            
        };
        return cell;
    }
    return Selectcell;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection6:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = NO;
    
    if (indexPath.row == 0) {
        CalcTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CalcCell];
        if (self.BuildingData.total_load > 0) {
            [cell setLoadData:[NSString stringWithFormat:@"%0.1f", self.BuildingData.total_load]];
        } else {
            [cell setLoadData:@""];
        }
        cell.calcClicked = ^{
            
        };
        return cell;
    } else if (indexPath.row == 1) {
        [cell setTitleStr:@"舒适性常开使用热负荷" andColor:nil andHintStr:nil andInputViewIsHidden:NO andInfoStr:nil andUnit:@"kW"];
        [cell setEditorText:@"200"];
    } else if (indexPath.row == 2) {
        [cell setTitleStr:@"舒适性间歇性使用热负荷" andColor:nil andHintStr:nil andInputViewIsHidden:NO andInfoStr:nil andUnit:@"kW"];
        [cell setEditorText:@"200"];
    } else {
        [cell setTitleStr:@"历史最低温度下热负荷" andColor:nil andHintStr:nil andInputViewIsHidden:NO andInfoStr:nil andUnit:@"kW"];
        [cell setEditorText:@"200"];
    }
    return cell;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection7:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = YES;
    
    if (indexPath.row == 0) {
        [cell setTitleStr:@"运行环温" andColor:nil andHintStr:@"请输入运行环境温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"℃"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 1) {
        [cell setTitleStr:@"供水温度" andColor:nil andHintStr:@"请输入供水温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"℃"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 2) {
        [cell setTitleStr:@"辅助热源开启环境温度" andColor:nil andHintStr:@"请输入环境温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"℃"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 3) {
        [cell setTitleStr:@"辅热需求" andColor:nil andHintStr:@"请输入辅热需求" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"kW"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 4) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        [cell setTitleStr:@"设备选型" andColor:BSBlackTextColor andHintStr:nil andInputViewIsHidden:YES andInfoStr:nil andUnit:nil];
        [cell setNavigationHint:@"手动选择"];
    } else {
        [cell setTitleStr:self.BuildingData.equip andColor:nil andHintStr:nil andInputViewIsHidden:NO andInfoStr:nil andUnit:@"台"];
        [cell setEditorText:[NSString stringWithFormat:@"%d", self.BuildingData.quantity]];
        cell.editorView.enabled = NO;
    }
    return cell;
}

// 运维分析
-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection8:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = YES;
    
    if (indexPath.row == 0) {
        UITableViewCell *Selectcell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"SelectArea_Cell"];
        Selectcell.textLabel.textColor = CM_TABLE_TITLE_COLOR;
        Selectcell.textLabel.font = [UIFont systemFontOfSize:kListTitleFontSize];
        Selectcell.detailTextLabel.textColor = CM_TABLE_INFO_COLOR;
        
        Selectcell.textLabel.text = @"运维分析情况选择";
        Selectcell.detailTextLabel.text = @"新建热源";
        Selectcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return Selectcell;
    } else if (indexPath.row == 1) {
        [cell setTitleStr:@"运行周期" andColor:nil andHintStr:@"请输入运行周期" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"年"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 2) {
        [cell setTitleStr:@"当地平均水价" andColor:nil andHintStr:@"请输入环境温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/吨"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 3) {
        [cell setTitleStr:@"当地平均电价" andColor:nil andHintStr:@"请输入辅热需求" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/度"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    }
    return cell;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection9a:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = YES;
    
    if (indexPath.row == 0) {
        [cell setTitleStr:@"当前平均天然气价" andColor:nil andHintStr:@"请输入" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/m³"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 1) {
        [cell setTitleStr:@"当前生物质颗粒价" andColor:nil andHintStr:@"请输入" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/kg"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 2) {
        [cell setTitleStr:@"当前平均蒸汽价" andColor:nil andHintStr:@"请输入环境温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/吨"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 3) {
        [cell setTitleStr:@"当前平均乙醇价" andColor:nil andHintStr:@"请输入" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/kG"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 4) {
        [cell setTitleStr:@"当前集中供暖单价" andColor:nil andHintStr:@"请输入" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/㎡/年"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    }
    return cell;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForSection10:(NSIndexPath *)indexPath {
    EditorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCell];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [cell setEditorText:@""];
    cell.TextFiledEditingEndBlock = nil;
    cell.editorView.enabled = YES;
    
    if (indexPath.row == 0) {
        [cell setTitleStr:@"热泵主机维护单价" andColor:nil andHintStr:@"请输入" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/台"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 1) {
        [cell setTitleStr:@"锅炉本体维护单价" andColor:nil andHintStr:@"请输入" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/台"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 2) {
        [cell setTitleStr:@"水泵维护单价" andColor:nil andHintStr:@"请输入环境温度" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/台"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    } else if (indexPath.row == 3) {
        [cell setTitleStr:@"管道系统维护单价" andColor:nil andHintStr:@"请输入" andInputViewIsHidden:NO andInfoStr:nil andUnit:@"元/套"];
        if (self.BuildingData.room_design_t != 0) {
            [cell setEditorText:[NSString stringWithFormat:@"%0.1f", self.BuildingData.room_design_t]];
        }
        [cell setKeyboardType:UIKeyboardTypeDecimalPad];
        cell.TextFiledValueBlock = ^(NSString *value){
            if ([value doubleValue] > 0) {
                self.BuildingData.room_design_t = [value doubleValue];
            }
        };
    }
    return cell;
}

- (UIView *)setupTitleView:(NSString *)title {
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, SECTION_TITLE_HEIGHT)];
    UILabel *lbTitle = [UILabel labelSingleLineboldFontSize:16 content:title];
    lbTitle.textColor = BSBlackTextColor;
    lbTitle.centerY = SECTION_TITLE_HEIGHT/2;
    lbTitle.centerX = kScreen_Width/2;
    [view addSubview:lbTitle];
    return view;
}

- (UIView *)coeffView {
    if (_coeffView == nil) {
        _coeffView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 240 + DEFAULT_SECTION_HEIGHT)];
        _coeffView.backgroundColor = [UIColor whiteColor];
        
        UITapLabel *lb1 = [[UITapLabel alloc]init];
        lb1.text = @"墙体传热系数";
        lb1.width = [Tools sizeOfSingleLineText:lb1.text withSize:15].width + 5;
        lb1.height = [Tools sizeOfSingleLineText:lb1.text withSize:15].height;
        [lb1 addTargetsBlock:^(id obj) {
            [self.textField1 becomeFirstResponder];
        }];
        lb1.font = [UIFont systemFontOfSize:15];
        lb1.textColor = CM_TABLE_TITLE_COLOR;
        lb1.x = 30;
        lb1.centerY = 20;
        [_coeffView addSubview:lb1];
        
        UILabel *lb11 = [UILabel labelSingleLineFontSize:13 content:@"W/(㎡·K)"];
        lb11.textColor = BSBlackTextColor;
        lb11.x = kScreen_Width - lb11.width - CELL_PADDING_RIGHT;
        lb11.centerY = 20;
        [_coeffView addSubview:lb11];
        
        self.textField1 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lb1.frame) + 5, lb1.y, lb11.x - CGRectGetMaxX(lb1.frame) - 10, lb1.height)];
        self.textField1.textColor = CM_TABLE_DETAIL_COLOR;
        self.textField1.font = [UIFont systemFontOfSize:kListTitleFontSize];
        self.textField1.keyboardType = UIKeyboardTypeDecimalPad;
        self.textField1.textAlignment = NSTextAlignmentRight;
        [self.textField1 addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        self.textField1.inputAccessoryView = [self addToolbar:1];
        if (self.BuildingData.es_coeff1 > 0) {
            self.textField1.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff1];
        }
        [_coeffView addSubview:self.textField1];
        
        UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(lb1.x, 40, kScreen_Width - lb1.x, 1)];
        line1.backgroundColor =  UIColor16(0xEEEEEE);
        [_coeffView addSubview:line1];
        
        UITapLabel *lb2 = [[UITapLabel alloc]init];
        lb2.text = @"门窗玻璃传热系数";
        lb2.width = [Tools sizeOfSingleLineText:lb2.text withSize:15].width + 5;
        lb2.height = [Tools sizeOfSingleLineText:lb2.text withSize:15].height;
        [lb2 addTargetsBlock:^(id obj) {
            [self.textField2 becomeFirstResponder];
        }];
        lb2.font = [UIFont systemFontOfSize:15];
        lb2.textColor = CM_TABLE_TITLE_COLOR;
        lb2.x = 30;
        lb2.centerY = 60;
        [_coeffView addSubview:lb2];
        
        UILabel *lb22 = [UILabel labelSingleLineFontSize:13 content:@"W/(㎡·K)"];
        lb22.textColor = BSBlackTextColor;
        lb22.x = kScreen_Width - lb22.width - CELL_PADDING_RIGHT;
        lb22.centerY = 60;
        [_coeffView addSubview:lb22];
        
        self.textField2 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lb2.frame) + 5, lb2.y, lb22.x - CGRectGetMaxX(lb2.frame) - 10, lb2.height)];
        self.textField2.textColor = CM_TABLE_DETAIL_COLOR;
        self.textField2.font = [UIFont systemFontOfSize:kListTitleFontSize];
        self.textField2.keyboardType = UIKeyboardTypeDecimalPad;
        self.textField2.textAlignment = NSTextAlignmentRight;
        [self.textField2 addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        self.textField2.inputAccessoryView = [self addToolbar:2];
        if (self.BuildingData.es_coeff2 > 0) {
            self.textField2.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff2];
        }
        [_coeffView addSubview:self.textField2];
        
        UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(lb2.x, 80, kScreen_Width - lb2.x, 1)];
        line2.backgroundColor =  UIColor16(0xEEEEEE);
        [_coeffView addSubview:line2];
        
        UITapLabel *lb3 = [[UITapLabel alloc]init];
        lb3.text = @"屋顶传热系数";
        lb3.width = [Tools sizeOfSingleLineText:lb3.text withSize:15].width + 5;
        lb3.height = [Tools sizeOfSingleLineText:lb3.text withSize:15].height;
        [lb3 addTargetsBlock:^(id obj) {
            [self.textField3 becomeFirstResponder];
        }];
        lb3.font = [UIFont systemFontOfSize:15];
        lb3.textColor = CM_TABLE_TITLE_COLOR;
        lb3.x = 30;
        lb3.centerY = 100;
        [_coeffView addSubview:lb3];
        
        UILabel *lb33 = [UILabel labelSingleLineFontSize:13 content:@"W/(㎡·K)"];
        lb33.textColor = BSBlackTextColor;
        lb33.x = kScreen_Width - lb33.width - CELL_PADDING_RIGHT;
        lb33.centerY = 100;
        [_coeffView addSubview:lb33];
        
        self.textField3 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lb3.frame) + 5, lb3.y, lb33.x - CGRectGetMaxX(lb3.frame) - 10, lb3.height)];
        self.textField3.textColor = CM_TABLE_DETAIL_COLOR;
        self.textField3.font = [UIFont systemFontOfSize:kListTitleFontSize];
        self.textField3.keyboardType = UIKeyboardTypeDecimalPad;
        self.textField3.textAlignment = NSTextAlignmentRight;
        [self.textField3 addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
        self.textField3.inputAccessoryView = [self addToolbar:3];
        if (self.BuildingData.es_coeff3 > 0) {
            self.textField3.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff3];
        }
        [_coeffView addSubview:self.textField3];
        
        UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(lb3.x, 120, kScreen_Width - lb3.x, 1)];
        line3.backgroundColor =  UIColor16(0xEEEEEE);
        [_coeffView addSubview:line3];
        

        UITapLabel *lb6 = [[UITapLabel alloc]init];
        lb6.text = @"传热系数填写指引：";
        lb6.width = [Tools sizeOfSingleLineText:lb6.text withSize:13].width + 5;
        lb6.height = [Tools sizeOfSingleLineText:lb6.text withSize:13].height;
        lb6.font = [UIFont systemFontOfSize:13];
        lb6.textColor = CM_BLUE_COLOR;
        lb6.x = 30;
        lb6.centerY = 140;
        [_coeffView addSubview:lb6];
        
        NSString *msg = @"※传热系数请咨询设计施工方，如无法获取请根据以下材质情况进行填写。\n\n混凝土墙（普通砂浆/绝热砂浆）——3（2.7/1.6）\n\n180砖墙（普通砂浆/绝热砂浆）——3（2.7/1.6）\n\n240砖墙（普通砂浆/绝热砂浆）——2.7（2.4/1.5）\n\n370砖墙（普通砂浆/绝热砂浆）——1.8（1.5/1.0）\n\n玻璃/窗(单层/双）——6.4/4.0\n\n大棚薄膜（单/充气）——6.8/4.0\n\n夹心苯板（5cm/10cm）——0.6/0.35\n\n阳光板（6cm/8cm/10cm/16cm）——3.5/3.3/3.0/2.7";
        
        UILabel *tips = [UILabel labelMultiLineFontSize:12 content:msg labelWidth:kScreen_Width - 50];
        tips.x = 30;
        tips.y = CGRectGetMaxY(lb6.frame) + 10;
        [_coeffView addSubview:tips];
        
        _coeffView.height = CGRectGetMaxY(tips.frame) + 15;
    } else {
        if (self.BuildingData.es_coeff1 > 0) {
            self.textField1.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff1];
        } else {
            self.textField1.text = @"";
        }
        if (self.BuildingData.es_coeff2 > 0) {
            self.textField2.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff2];
        } else {
            self.textField2.text = @"";
        }
        if (self.BuildingData.es_coeff3 > 0) {
            self.textField3.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff3];
        } else {
            self.textField3.text = @"";
        }
        if (self.BuildingData.es_coeff4 > 0) {
            self.textField4.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff4];
        } else {
            self.textField4.text = @"";
        }
        if (self.BuildingData.es_coeff5 > 0) {
            self.textField5.text = [NSString stringWithFormat:@"%0.2f", self.BuildingData.es_coeff5];
        } else {
            self.textField5.text = @"";
        }
    }
    return _coeffView;
}

- (UIView *)tipView1 {
    if (!_tipView1) {
        _tipView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 0)];
        _tipView1.backgroundColor = [UIColor whiteColor];
        
        UITapLabel *lb6 = [[UITapLabel alloc]init];
        lb6.text = @"当地基础室外参数：";
        lb6.width = [Tools sizeOfSingleLineText:lb6.text withSize:13].width + 5;
        lb6.height = [Tools sizeOfSingleLineText:lb6.text withSize:13].height;
        lb6.font = [UIFont systemFontOfSize:13];
        lb6.textColor = CM_BLUE_COLOR;
        lb6.x = 30;
        lb6.y = 10;
        [_tipView1 addSubview:lb6];
        
        NSString *msg = @"采暖室外计算温度：-12℃\n\n冬季空气调节室外计算温度：-15℃\n\n极端最低温度值：-23.3℃\n\n※取值建议：\n\n常规舒适性采暖全天开启的，选采暖计算温度；\n\n间歇性或每天阶段性开启的，选冬季空气调节计算温度；\n\n工艺性温度要求场所，选计算最低温度。\n\n另外山区、郊外等地温度宜降低3~5℃；仅白天使用场所可提高2~3℃。";
        UILabel *tips = [UILabel labelMultiLineFontSize:12 content:msg labelWidth:kScreen_Width - 50];
        tips.x = 30;
        tips.y = CGRectGetMaxY(lb6.frame) + 10;
        [_tipView1 addSubview:tips];
        
        _tipView1.height = CGRectGetMaxY(tips.frame) + 15;
    }
    return _tipView1;
}

- (UIView *)tipView2 {
    if (!_tipView2) {
        _tipView2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 0)];
        _tipView2.backgroundColor = [UIColor whiteColor];
        
        UITapLabel *lb6 = [[UITapLabel alloc]init];
        lb6.text = @"水温要求推荐：";
        lb6.width = [Tools sizeOfSingleLineText:lb6.text withSize:13].width + 5;
        lb6.height = [Tools sizeOfSingleLineText:lb6.text withSize:13].height;
        lb6.font = [UIFont systemFontOfSize:13];
        lb6.textColor = CM_BLUE_COLOR;
        lb6.x = 30;
        lb6.y = 10;
        [_tipView2 addSubview:lb6];
        
        NSString *msg = @"※如设计院或客户未指定水温，宜按下列水温选择。\n\n地暖——45/35℃；\n\n风盘——50/45℃；\n\n暖气——55/45℃。\n\n三者同时存在时，取温度最高者";
        UILabel *tips = [UILabel labelMultiLineFontSize:12 content:msg labelWidth:kScreen_Width - 50];
        tips.x = 30;
        tips.y = CGRectGetMaxY(lb6.frame) + 10;
        [_tipView2 addSubview:tips];
        
        _tipView2.height = CGRectGetMaxY(tips.frame) + 15;
    }
    return _tipView2;
}

- (UIView *)tipView3 {
    if (!_tipView3) {
        _tipView3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 0)];
        _tipView3.backgroundColor = [UIColor whiteColor];
        
        
        NSString *msg = @"※无需运行费用分析时，水温和时间可忽略";
        UILabel *tips = [UILabel labelMultiLineFontSize:12 content:msg labelWidth:kScreen_Width - 50];
        tips.x = 30;
        tips.y = 10;
        [_tipView3 addSubview:tips];
        
        _tipView3.height = CGRectGetMaxY(tips.frame) + 15;
    }
    return _tipView3;
}

- (UIView *)tipView4 {
    if (!_tipView4) {
        _tipView4 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 0)];
        _tipView4.backgroundColor = [UIColor whiteColor];
        
        UITapLabel *lb6 = [[UITapLabel alloc]init];
        lb6.text = @"注意：";
        lb6.width = [Tools sizeOfSingleLineText:lb6.text withSize:13].width + 5;
        lb6.height = [Tools sizeOfSingleLineText:lb6.text withSize:13].height;
        lb6.font = [UIFont systemFontOfSize:13];
        lb6.textColor = CM_BLUE_COLOR;
        lb6.x = 30;
        lb6.y = 10;
        [_tipView4 addSubview:lb6];
        
        NSString *msg = @"1.运行环温默认采暖计算温度-3℃，可根据情况调整；\n\n 2.供水温度默认使用要求中“供水温度”，可修改；\n\n3.勾选辅热开启环境温度默认“运行环温”，可修改；";
        UILabel *tips = [UILabel labelMultiLineFontSize:12 content:msg labelWidth:kScreen_Width - 50];
        tips.x = 30;
        tips.y = CGRectGetMaxY(lb6.frame) + 10;
        [_tipView4 addSubview:tips];
        
        _tipView4.height = CGRectGetMaxY(tips.frame) + 15;
    }
    return _tipView4;
}

- (UIToolbar *)addToolbar:(NSInteger)tag
{
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 35)];
    toolbar.tintColor = [UIColor blueColor];
    toolbar.backgroundColor = [UIColor colorWithRed:160/255.0 green:160/255.0 blue:160/255.0 alpha:1.0];
    toolbar.tag = tag;
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(textFieldDone:)];
    bar.tag = tag;
    toolbar.items = @[space, bar];
    return toolbar;
}

- (void)textFieldChanged:(id)textField {
    
}

- (void)textFieldDone:(UIBarButtonItem*)bar {
    NSInteger tag = bar.tag;
    if (tag == 1) {
        [self.textField1 resignFirstResponder];
    } else if (tag == 2) {
        [self.textField2 resignFirstResponder];
    } else if (tag == 3) {
        [self.textField3 resignFirstResponder];
    } else if (tag == 4) {
        [self.textField4 resignFirstResponder];
    } else if (tag == 5) {
        [self.textField5 resignFirstResponder];
    }
}


- (void)selectTerminalType {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"选择末端类型" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"风盘" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.terminal_type = 0;
        self.BuildingData.water_out_t = 50;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 2) withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"地暖" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.terminal_type = 1;
        self.BuildingData.water_out_t = 45;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 2) withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"暖气片" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.terminal_type = 2;
        self.BuildingData.water_out_t = 55;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 2) withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"其他" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.terminal_type = 3;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

- (void)selectHeatType {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"选择采暖类型" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"舒适性采暖" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.heat_type = 0;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"工艺性采暖" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.heat_type = 1;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(2, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

- (void)selectIsEsBuilding {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"是否是节能建筑" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"是" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.es_building = 1;
        //        [self.tableView reloadRowsAtIndexPaths:indexPathObj(3, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"否" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.es_building = 0;
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

- (void)selectBuildingCoeff {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"建筑外形" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"规则" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.is_regular = 1;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(3, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"不规则" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.is_regular = 0;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(3, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

- (void)selectBuildingType {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"选择建筑性质" message: nil preferredStyle:UIAlertControllerStyleActionSheet];
    [alertController addAction: [UIAlertAction actionWithTitle:@"公建" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.building_type = 0;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"民建" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.building_type = 1;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"厂房" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.building_type = 2;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle:@"其他" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        self.BuildingData.building_type = 13;
        [self.tableView reloadRowsAtIndexPaths:indexPathObj(1, 0) withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    [self presentViewController: alertController animated: YES completion: nil];
}

/**
 时间日期选择
 
 @param title 标题
 @param date 默认日期
 @param cb 回调
 */
- (void)chooseDate:(NSString*)title andDate:(NSDate*)date andCb:(void (^)(NSDate *date))cb{
    CustomIOSAlertView *alert = [[CustomIOSAlertView alloc] init];
    [alert setUseMotionEffects:YES];
    
    UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width-50, 0)];
    
    //标题栏
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, subView.width, 50)];
    [titleView setUserInteractionEnabled:YES];
    
    titleView.backgroundColor = CM_DARKGREEN_COLOR;
    [subView addSubview:titleView];
    //左上角、右上角圆角为7
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:titleView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(7, 7)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = titleView.bounds;
    maskLayer.path = maskPath.CGPath;
    titleView.layer.mask = maskLayer;
    
    //添加文字
    UILabel *titleLabel = [UILabel labelSingleLineFontSize:14 content:title];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.centerY = titleView.centerY;
    titleLabel.centerX = titleView.centerX;
    [titleView addSubview:titleLabel];
    
    //选择日期
    UIDatePicker *datePicker = [[UIDatePicker alloc] init];
    datePicker.datePickerMode = UIDatePickerModeDate;
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];//设置为中文显示
    datePicker.locale = locale;
    if (date == nil) {
        datePicker.date = [NSDate date];
    }
    else {
        datePicker.date = date;
    }
    
    if (datePicker.superview == nil) {
        //此处将Y坐标设在最底下，为了一会动画的展示
        datePicker.frame = CGRectMake(0, titleView.height, subView.width, 216);
        [subView addSubview:datePicker];
    }
    subView.height = CGRectGetMaxY(datePicker.frame);
    
    [alert setContainerView:subView];
    [alert setButtonTitles:@[@"确定", @"取消"]];
    alert.closeOnTouchUpOutside = NO;
    @weakObj(alert)
    [alert setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
        switch (buttonIndex) {
            case 1:
                //取消选择
                if (cb) {
                    //                    cb(nil);
                }
                [Weakalert close];
                break;
            case 0:
            {
                NSDate *selectedDate = datePicker.date;
                if (cb) {
                    cb(selectedDate);
                }
                [Weakalert close];
            }
                break;
            default:
                break;
        }
    }];
    [alert show];
}

@end
